package com.bingxue.edu.management.report.controller;

import com.bingxue.edu.framework.common.model.Response;
import com.bingxue.edu.framework.security.ApiResource;
import com.bingxue.edu.management.report.model.query.MonthlyTeacherLessonQuery;
import com.bingxue.edu.management.report.model.resp.MonthlyTeacherLessonResp;
import com.bingxue.edu.management.report.service.MonthlyTeacherLessonService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "教师课时月报")
@RestController
@RequestMapping("/report/teacher-lesson")
@RequiredArgsConstructor
public class TeacherLessonReportController {

    private final MonthlyTeacherLessonService monthlyTeacherLessonService;

    @ApiResource("report:teacher-lesson:read")
    @GetMapping("/list")
    public Response<List<MonthlyTeacherLessonResp>> getMonthlyTeacherLessonList(@Validated MonthlyTeacherLessonQuery query) {
        return Response.success(monthlyTeacherLessonService.getMonthlyTeacherLessonList(query));
    }

    @ApiResource("report:teacher-lesson:read")
    @PostMapping("/compute")
    public Response<Void> computeTeacherLessonReport(@RequestBody @Validated MonthlyTeacherLessonQuery query) {
        monthlyTeacherLessonService.computeTeacherLessonReport(query.getMonth());
        return Response.success();
    }
}
